<?php namespace Home\Controller; 

//会员中心控制器
class MemberController extends CommonController{

	//构造函数
	public function __init()
	{
		parent::__init();
	}
	
	public function index(){
		View::make();
	}
	
//	我的订单信息
	public function orderList(){
//		p($_SESSION);die;
		$uid=$_SESSION['uid'];
		
//		查询订单表，当前用户的所有订单数据
		$data=Db::table('shop_order sor')
		->join('shop_order_list orli','sor.oid','=','orli.oid')
		->where('uid',$uid)
		->groupBy('sor.oid')
		->get();

          foreach($data as $k=>$v){
          	$data[$k]['order_one']=Db::table('shop_order_list orli')
			                        ->join('shop_order sor','orli.oid','=','sor.oid')
									->where('uid',$uid)
									->where('sor.oid',$v['oid'])
          	                        ->get();
          }
//		p($data);die;
		View::with('data',$data);
		View::make();
	}
	
	
//	//	确认收货方法
	public function shouhuo(){
		$oid=Q('get.oid',0,'intval');
//		var_dump($oid);die;
//		改变订单状态
		$result=Db::table('shop_order')->where('oid',$oid)->where('uid',$_SESSION['uid'])->update(array('status'=>'已完成'));
		if(!$result){
			View::error('收货失败,写入失败');
		}
		View::success('收货成功',U('orderList'));
	}
	public function orderInfo(){
		$oid=Q('get.oid',0,'intval');
		$uaid=Db::table('shop_order')->where('oid',$oid)->pluck('uaid');
		$gdData=Db::table('user_address')->where('uaid',$uaid)->first();
//		p($gdData);die;
		View::with('gdData',$gdData);
		$uid=$_SESSION['uid'];
		
//		查询订单表，当前用户的所有订单数据
		$data=Db::table('shop_order sor')
		->join('shop_order_list orli','sor.oid','=','orli.oid')
		->where('uid',$uid)
		->where('sor.oid',$oid)
		->groupBy('sor.oid')
		->get();

          foreach($data as $k=>$v){
          	$data[$k]['order_one']=Db::table('shop_order_list orli')
			                        ->join('shop_order sor','orli.oid','=','sor.oid')
									->where('uid',$uid)
									->where('sor.oid',$oid)
          	                        ->get();
        }
//		p($data);die;
		View::with('data',$data);
		View::make();
	}
	public function del(){
		$oid=Q('get.oid',0,'intval');
		var_dump($oid);die;
       
	}
		
//	
}
